package com.ifnk.portaljava.hlyt.test;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

public class Tshark2 {
	
	private static Log loger = LogFactory.getLog(Tshark2.class);
	private static String tshark_pcap;
	private static String pcapfilepath;
	private static String pcapfilepath2;
	private static String psml2;
	private static String pdml2;
	private static String pcapNativeFile;
	private static String pcapNativeFile2;
	
	private static String separator;
	
	static {
		Locale locale = Locale.ENGLISH;
		ResourceBundle localResource = ResourceBundle.getBundle("Socket",
				locale);
		tshark_pcap = localResource.getString("tshark_pcap");
		pcapfilepath2 = localResource.getString("pcapfilepath2");
		psml2 = localResource.getString("psml");
		pdml2 = localResource.getString("pdml");
		pcapNativeFile2 = localResource.getString("pcapNativeFile2");
		
		pcapfilepath = localResource.getString("pacpfilepath");
		pcapNativeFile = localResource.getString("pcapNativeFile");
		
		
		separator = localResource.getString("separator");
		
		
	}
	
	public static void mergepcap(String[] files, String sessionid) {
		
		if (files.length == 0) {
			return;
		}
		
		
		File file = new File(pcapfilepath + "summary" + separator + sessionid);
		if (!file.exists()) {
			file.mkdirs();
		}
		
		StringBuffer sb = new StringBuffer();
		
		sb.append(tshark_pcap + " ");
		
		sb.append(" -w " + pcapfilepath + "summary" + separator + sessionid + separator + "all.pcap -F pcap " + pcapfilepath2 +  files[0] + ".pcap ");
		for (int i = 1; i < files.length; i++) {
			sb.append(pcapfilepath2 + files[1] + ".pcap ");
		}
		
		try {
			System.out.println("sb ="+sb.toString());
			Process process = Runtime.getRuntime().exec(sb.toString());
			Thread.sleep(2000);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}
